package com.xnyzc.lhy.finance.controller.bill;


import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.finance.entity.bill.OaDBill;
import com.xnyzc.lhy.finance.params.dto.bill.OaBillIdDTO;
import com.xnyzc.lhy.finance.params.dto.bill.OaBillTypeDTO;
import com.xnyzc.lhy.finance.params.dto.bill.OaDriverBillDTO;
import com.xnyzc.lhy.finance.service.bill.IOaDBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 司机账单表 前端控制器
 * </p>
 *
 * @author cuixiaojian
 * @since 2019-10-16
 */
@RestController
@RequestMapping("/finance/oa-dbill")
public class OaDBillController {

    @Autowired
    private IOaDBillService iOaDBillService;

    @PostMapping("getBillType")
    public Rv getBillType(
            @RequestBody OaBillTypeDTO oaBillTypeDTO
            ) {
        if (CheckUtil.objIsEmpty(oaBillTypeDTO)) {
            throw PangException.create(EErrorCode.missingArg);
        }
        return iOaDBillService.getBillType(oaBillTypeDTO.getBillType());
    }

    /**
     * 获取本司机账单信息
     * @param oaDriverBillDTO 入参DTO
     * @return List -> data
     */
    @PostMapping("getDriverBill")
    public Rv getDriverBill(@RequestBody OaDriverBillDTO oaDriverBillDTO) {
        if (CheckUtil.objIsEmpty(oaDriverBillDTO.getDriverId())) {
            Long driverId = TokenUtil.getTokenUserId();
            oaDriverBillDTO.setDriverId(driverId);
        }
        return iOaDBillService.getDriverBillDetial(oaDriverBillDTO);
    }

    /**
     * 获取账单详情
     * @param oaBillIdDTO 账单ID
     * @return Object
     */
    @PostMapping("getDriverBillInfo")
    public Rv getDriverBillInfo(
            @RequestBody OaBillIdDTO oaBillIdDTO
            ) {

        if (CheckUtil.objIsEmpty(oaBillIdDTO)) {
            throw PangException.create(EErrorCode.missingArg);
        }

        return iOaDBillService.getDriverBillInfo(Long.parseLong(oaBillIdDTO.getBillId()));

    }

    /**
     * 添加账单记录
     * @param oaDBill 账单详情
     * @return
     */
    @PostMapping("saveDriverBill")
    public Rv saveDriverBill(@RequestBody OaDBill oaDBill) {
        return iOaDBillService.saveDriverBill(oaDBill);
    }


}
